package interviewpreparationkit.stringmanipulation

/**
 * [Strings: Making Anagrams](https://www.hackerrank.com/challenges/ctci-making-anagrams)
 */
fun makeAnagram(a: String, b: String): Int {
    val bucket = Array(26) { 0 }
    a.forEach { bucket[it - 'a']++ }
    b.forEach { bucket[it - 'a']-- }

    return bucket.sumBy { kotlin.math.abs(it) }
}

/**
 * [Alternating Characters](https://www.hackerrank.com/challenges/alternating-characters)
 */
fun alternatingCharacters(s: String): Int {
    var ans = 0
    var pre = 'C'
    s.forEach {
        if (it == pre) {
            ans++
        }
        pre = it
    }

    return ans
}